package com.ruoyi.marketers.controller;

import java.util.List;
import java.io.IOException;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.file.FileUtils;
import com.ruoyi.marketers.domain.MarketersShop;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.marketers.domain.MarketersApply;
import com.ruoyi.marketers.service.IMarketersApplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商家审核Controller
 * 
 * @author ruoyi
 * @date 2023-10-21
 */
@RestController
@RequestMapping("/MarketersApply")
public class MarketersApplyController extends BaseController
{
    @Autowired
    private IMarketersApplyService marketersApplyService;

    /**
     * 查询商家审核列表
     */
    @RequiresPermissions("marketers:MarketersApply:list")
    @GetMapping("/list")
    public TableDataInfo list(MarketersApply marketersApply)
    {
        startPage();
        List<MarketersApply> list = marketersApplyService.selectMarketersApplyList(marketersApply);
        return getDataTable(list);
    }

    /**
     * 导出商家审核列表
     */
    @RequiresPermissions("marketers:MarketersApply:export")
    @Log(title = "商家审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MarketersApply marketersApply)
    {
        List<MarketersApply> list = marketersApplyService.selectMarketersApplyList(marketersApply);
        ExcelUtil<MarketersApply> util = new ExcelUtil<MarketersApply>(MarketersApply.class);
        util.exportExcel(response, list, "商家审核数据");
    }

    /**
     * 获取商家审核详细信息
     */
    @RequiresPermissions("marketers:MarketersApply:query")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(marketersApplyService.selectMarketersApplyByApplyId(applyId));
    }
    /**
     * 获取店铺详细信息
     */

    @RequiresPermissions("marketers:shop:query")
    @GetMapping(value = "/shopsId/{shopsId}")
    public MarketersShop getInfo1(@PathVariable("shopsId") Long shopsId)
    {
        System.out.println(shopsId);
        return marketersApplyService.selectShopByShopsId(shopsId);
    }
    /**
     * 新增商家审核
     */
    @RequiresPermissions("marketers:MarketersApply:add")
    @Log(title = "商家审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MarketersApply marketersApply)
    {
        return toAjax(marketersApplyService.insertMarketersApply(marketersApply));
    }
    /**
     * 新增店铺
     */
    @RequiresPermissions("marketers:MarketersApply:add")
    @Log(title = "商家审核", businessType = BusinessType.INSERT)
    @PostMapping("/addShop")
    public AjaxResult addShop(@RequestBody MarketersShop marketersApply)
    {
        System.out.println(marketersApply+".....");
        return toAjax(marketersApplyService.insertShop(marketersApply));
    }
    /**
     * 修改商家审核
     */
    @RequiresPermissions("marketers:MarketersApply:edit")
    @Log(title = "商家审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MarketersApply marketersApply)
    {
        return toAjax(marketersApplyService.updateMarketersApply(marketersApply));
    }

    /**
     * 删除商家审核
     */
    @RequiresPermissions("marketers:MarketersApply:remove")
    @Log(title = "商家审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long applyIds)
    {
        System.out.println(applyIds);
        return toAjax(marketersApplyService.deleteShopsApplyByShopsId(applyIds));
    }

    /**
     * 删除商家审核
     */
    @RequiresPermissions("marketers:MarketersApply:remove")
    @Log(title = "商家审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{shopsId}")
    public AjaxResult removeByShopsId(@PathVariable Long shopsId)
    {
        return toAjax(marketersApplyService.deleteShopsApplyByShopsId(shopsId));
    }
    /**
     * 查询店铺列表
     */
    @RequiresPermissions("marketers:shop:list")
    @PostMapping("/list")
    public List<MarketersApply> getShopProfile(@RequestBody MarketersApply marketers)
    {
        //startPage();
        System.out.println(marketers);
        List<MarketersApply> list = marketersApplyService.selectShopList(marketers);
        return list;
    }

}
